package com.app.Activity;

import com.app.Controller.NetworkController;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import app.com.ModuleRole.R;

public class frmThaoLuanActivity extends Activity {
	Button btnGui;
	TextView txtNoiDungChat;
	ListView lvChat;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_thao_luan);
		btnGui=(Button)findViewById(R.id.btnGui);
		txtNoiDungChat=(TextView)findViewById(R.id.txtNoiDungChat);
		lvChat=(ListView)findViewById(R.id.lvChat);
		txtNoiDungChat.setSingleLine();
		txtNoiDungChat.setOnKeyListener(new OnKeyListener() {
			
			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				if(keyCode==66){
					sendChat();
				}
				return false;
			}
		});
	}
	private void sendChat(){
		Toast.makeText(getBaseContext(), txtNoiDungChat.getText(), 1).show();
		txtNoiDungChat.setText("");
		txtNoiDungChat.setFocusable(true);
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		new MenuInflater(getApplication()).inflate(R.menu.omnu_thao_luan, menu);
		return (super.onCreateOptionsMenu(menu));
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int id = item.getItemId();
		switch (id) {
		case R.id.mnuDanhSachThanhVien:
			Intent iThaoLuan=new Intent(getBaseContext(),frmDanhSachThanhVienActivity.class);
			startActivity(iThaoLuan);
			break;		
		case R.id.mnuChiaSeTaiLieu:
			Toast.makeText(getBaseContext(), "Chia sẻ tài liệu", 1).show();
			break;
		default:
			break;
		}
		return true;
	}
	@Override
	public void onStart(){
		super.onStart();
		if(NetworkController._peer!=null)
			NetworkController.resetRole();
	}
}
